# Contributor: Clayton Craft <clayton@craftyguy.net>
# Maintainer: Clayton Craft <clayton@craftyguy.net>
pkgname=widelands
pkgver=1.0
pkgrel=8
pkgdesc="realtime strategy game with emphasis on economy and transport"
url="https://widelands.org"
arch="all !s390x" # nobody will use s390x to place widelands
license="GPL-2.0-or-later"
depends="lua python3"
makedepends="
	boost-dev
	cmake
	curl-dev
	dbus-dev
	doxygen
	freeglut-dev
	gettext-dev
	glew-dev
	graphviz
	libexecinfo-dev
	libintl
	libpng-dev
	ninja
	sdl2-dev
	sdl2_image-dev
	sdl2_mixer-dev
	sdl2_net-dev
	sdl2_ttf-dev
	zlib-dev
"
source="https://github.com/widelands/widelands/archive/v$pkgver/widelands-v$pkgver.tar.gz
	widelands.desktop
	widelands.png
	0001-link-libintl.patch
	0002-linux-only-enable-backtrace-when-using-glibc.patch
	boost-1.77.patch
	"
subpackages="$pkgname-doc"

build() {
	cmake -B output \
		-Wno-dev \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DWL_INSTALL_BASEDIR=/usr \
		-DWL_INSTALL_DATADIR=/usr/share/widelands \
		-G Ninja
	cmake --build output
}

check() {
	cd output
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install output

	mkdir -p "$pkgdir"/usr/bin
	for _exe in widelands wl_create_spritesheet wl_map_object_info wl_map_info; do
		mv "$pkgdir/usr/$_exe" "$pkgdir"/usr/bin/
	done

	mkdir -p "$pkgdir"/usr/share/doc/"$pkgname"
	for _file in VERSION ChangeLog CREDITS; do
		mv "$pkgdir/usr/$_file" "$pkgdir"/usr/share/doc/"$pkgname"
	done

	mkdir -p "$pkgdir"/usr/share/licenses/$pkgname
	mv "$pkgdir"/usr/COPYING "$pkgdir"/usr/share/licenses/"$pkgname"

	install -Dm644 "$srcdir"/$pkgname.png "$pkgdir"/usr/share/pixmaps/$pkgname.png
	install -Dm644 "$srcdir"/$pkgname.desktop "$pkgdir"/usr/share/applications/$pkgname.desktop
}
sha512sums="
1092750944a8669682097dfbd2b578cdb8fab377f32cb81ce8d85b9d9b2e8ae8c4c73500c0a89be649b360fd7e086e19595eba37cecb8d64679e46f7da13e46e  widelands-v1.0.tar.gz
9100b2430ee195f17e80e6096c89450792bc97d235b4c3fd596f6bef6d08ea6cbd5d722d8dbc48280663808a8ed56c496681581e195e443208f819c2919ba102  widelands.desktop
f7db9d7584ec8431f2f1857baddeb32cd3ae182343e7f0369e61fb444514bd9c2e6a3931ae34f24cc994840dffbbe4451f33845798f3d582f41b31f451b261ac  widelands.png
645bae9804dab9a372176b070797c51a6720cb7372e786b3eab868fada63c7b7ddf6815b687886267d13cfe90c0ecf7516e44b3f5c921a0024c1a30e0fb87344  0001-link-libintl.patch
f0ead2f77191621c5b46c90884f5b1495f8d4ff8cbf2acfc31e2f9586f3358a96ce3eea410f9ed9f8017b12ee856f5224b77a7b1f12e8cf1c04a044b57f1c6c3  0002-linux-only-enable-backtrace-when-using-glibc.patch
d0eb9ae394a3e33aa7b53da408e233f2f856e88040252771bd0216a7c103ef8759377e165c4fbcbdf4de950e991b08d1e876a6dcc24bc9302d7ebb35fd5ba3bb  boost-1.77.patch
"
